package chainOfResponsibility;

import gameBasics.GameObject;
import object.Iron;
import tank.EnemyTank;
import tank.Tank;

public class ETankIronCollider implements Collider{

    /**
     * 敌对坦克与铁块碰撞
     * @param o1 坦克对象
     * @param o2 铁块对象
     */
    @Override
    public boolean collide(GameObject o1, GameObject o2) {
        if(o1 instanceof EnemyTank enemyTank && o2 instanceof Iron iron){
            collideWith(enemyTank, iron);
        } else if (o1 instanceof Iron && o2 instanceof Tank) {
            collide(o2, o1);
        }

        return true;
    }

    /**
     * 敌对坦克与铁块的碰撞检测
     * @param enemyTank 敌对坦克对象
     * @param iron 铁块对象
     */
    private void collideWith(EnemyTank enemyTank, Iron iron){
        if(enemyTank.getRectangle().intersects(iron.getRectangle())){
            enemyTank.back();
        }
    }

}
